package cn.schoolwow.quickdao.module.database.dql.condition.flow.set;

import cn.schoolwow.quickdao.module.database.dql.condition.flow.common.SetSingleJoinTableStatementFlow;
import cn.schoolwow.quickdao.module.database.dql.parent.domain.QueryContext;
import cn.schoolwow.quickdao.module.database.dql.subCondition.domain.SubQueryOption;
import cn.schoolwow.quickflow.domain.FlowContext;
import cn.schoolwow.quickflow.flow.BusinessFlow;

public class SetJoinTableFragmentFlow implements BusinessFlow {
    @Override
    public void executeBusinessFlow(FlowContext flowContext) throws Exception {
        QueryContext queryContext = (QueryContext) flowContext.checkData("queryContext");

        StringBuilder sqlBuilder = new StringBuilder();
        for(SubQueryOption subQueryOption:queryContext.queryOption.subQueryOptionList){
            flowContext.startFlow(new SetSingleJoinTableStatementFlow())
                    .putCurrentCompositeFlowData("subQueryOption", subQueryOption)
                    .putCurrentCompositeFlowData("sqlBuilder", sqlBuilder)
                    .execute();
        }
        if(sqlBuilder.length()>0){
            queryContext.join = sqlBuilder.toString();
        }
    }

    @Override
    public String name() {
        return "设置查询表语句片段";
    }

}
